'''//! `streams` 关键字的具体实现

use std::collections::HashMap;
use std::sync::{Arc, Mutex};

use crate::core::manifest::{ContributeDefinition, ContributionPointDefinition};
use crate::core::services::context::ActivateContext;
use crate::core::services::contribution_keyword_manager::IContributionKeyword;
use super::multicast_stream::MulticastStream;

/// 流系统的核心实现，负责管理所有 `MulticastStream` 实例
pub struct StreamsImplement {
    streams: Arc<Mutex<HashMap<String, Arc<MulticastStream>>>>,
}

impl StreamsImplement {
    pub fn new() -> Self {
        Self { streams: Arc::new(Mutex::new(HashMap::new())) }
    }

    pub fn get_stream(&self, name: &str) -> Option<Arc<MulticastStream>> {
        self.streams.lock().unwrap().get(name).cloned()
    }
}

impl IContributionKeyword for StreamsImplement {
    fn request_contribution(&self, _ctx: &ActivateContext, _definitions: &[ContributeDefinition]) {
        // 插件通过 get_stream_reader/writer 来“贡献”其作为消费者/生产者的能力
        // 此处无需处理
    }

    /// 当有插件定义一个新的“流”（贡献点）时，此方法被调用
    fn request_contribution_point(&self, ctx: &ActivateContext, definitions: &[ContributionPointDefinition]) {
        let mut streams = self.streams.lock().unwrap();
        for def in definitions {
            if !streams.contains_key(&def.name) {
                println!("StreamsImplement: Plugin '{}' created a new stream '{}'", ctx.contributor, def.name);
                let stream = Arc::new(MulticastStream::new(&def.name));
                streams.insert(def.name.clone(), stream);
            }
        }
    }
}
'''